package com.kuang.controller;

import com.kuang.pojo.AstControllerHeart;
import com.kuang.service.asset.AstControllerHeartService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstControllerHeartController {

    @Resource
    AstControllerHeartService astControllerHeartService;

    /**
     * 获取设备心跳数据
     * @param model
     * @return
     */
    @RequestMapping("getAstControllerHearts")
    public String getAstControllerHearts(Model model){
        List<AstControllerHeart> astControllerHearts = astControllerHeartService.selectAll();
        model.addAttribute("astControllerHearts",astControllerHearts);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "mqtt/ast_controller_heart_list";
    }

    /**
     * 获取设备心跳数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstControllerHeartsByExample")
    public String getAstControllerHeartsByExample(AstControllerHeart astControllerHeart,Model model){
        List<AstControllerHeart> astControllerHearts = astControllerHeartService.selectAllByExample(astControllerHeart);
        model.addAttribute("astControllerHearts",astControllerHearts);
        model.addAttribute("device_code",astControllerHeart.getDevice_code());
        model.addAttribute("ver",astControllerHeart.getVer());
        return "mqtt/ast_controller_heart_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstControllerHeartsById/{id}")
    public String getAstControllerHeartsById(@PathVariable("id") String id, Model model){
        AstControllerHeart astControllerHeart = new AstControllerHeart();
        astControllerHeart.setAst_controller_heart_id(id);
        List<AstControllerHeart> astControllerHearts = astControllerHeartService.selectAllByExample(astControllerHeart);
        model.addAttribute("astControllerHeart",astControllerHearts.get(0));
        return "mqtt/ast_controller_heart_from";
    }

}
